//
//  HXDNavigationController.swift
//  weibo
//
//  Created by huxuedong on 15/12/5.
//  Copyright © 2015年 huxuedong. All rights reserved.
//

import UIKit

class HXDNavigationController: UINavigationController, UIGestureRecognizerDelegate {

    override func viewDidLoad() {
        super.viewDidLoad()
        //设置手势代理滑动页面
        self.interactivePopGestureRecognizer?.delegate = self
    }
    
    //重写pushViewController，设置目标控制器的样式
    override func pushViewController(viewController: UIViewController, animated: Bool) {
        if childViewControllers.count != 0 {
            var title: String = "返回"
            if childViewControllers.count == 1 {
                title = childViewControllers.first?.title ?? title
            }
            viewController.navigationItem.leftBarButtonItem = UIBarButtonItem(imageName: "navigationbar_back_withtext", title: title, target: self, action: "back")
            viewController.hidesBottomBarWhenPushed = true
        }
        super.pushViewController(viewController, animated: true)
    }
    
    @objc private func back() {
        popViewControllerAnimated(true)
    }
    
    func gestureRecognizerShouldBegin(gestureRecognizer: UIGestureRecognizer) -> Bool {
        printLog("滑动页面")
        return childViewControllers.count != 1
    }

}
